const HTTP_REQUEST_URL = "https://icrcs.org"; // 请求地址

/***
 * 数据配置
 * 参数:{}
 */

function getIndexConfig(){
    return new Promise((resolve, reject) => {
        $.ajax({
            url: `${HTTP_REQUEST_URL}/api/index/config`,
            method:'get',
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            data:'',
            headers:{
                'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
            },
            success:(res)=>{
                resolve(res);
            },
            error:(err)=>{
                reject(err);
            },
            complete:(com)=>{
                console.log(com)
            }
        })
    });
}

/***
 * 捐赠表单提交
 * 参数:{data}
 */

function postSubmitForm(data){
    return new Promise((resolve, reject) => {
        $.ajax({
            url: `${HTTP_REQUEST_URL}/api/index/contribution`,
            method:'post',
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            data:data,
            headers:{
                'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
            },
            success:(res)=>{
                resolve(res);
            },
            error:(err)=>{
                reject(err);
            },
            complete:(com)=>{
                console.log(com)
            }
        })
    });
}


/***
 * 新闻列表
 * 参数:{data}
 */

function getNewsList(data){
    return new Promise((resolve, reject) => {
        $.ajax({
            url: `${HTTP_REQUEST_URL}/api/index/newslist`,
            method:'get',
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            data,
            headers:{
                'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
            },
            success:(res)=>{
                resolve(res);
            },
            error:(err)=>{
                reject(err);
            },
            complete:(com)=>{
                console.log(com)
            }
        })
    });
}

/***
 * 新闻详情
 * 参数:{id}
 */

function getNewsDetails(id){
    return new Promise((resolve, reject) => {
        $.ajax({
            url: `${HTTP_REQUEST_URL}/api/index/newsdetail/id/${id}`,
            method:'get',
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            data:{},
            headers:{
                'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
            },
            success:(res)=>{
                resolve(res);
            },
            error:(err)=>{
                reject(err);
            },
            complete:(com)=>{
                console.log(com)
            }
        })
    });
}